using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;

public class Node : MonoBehaviour
{
    [HideInInspector]
    public GameObject turret;
    
    public static Vector3 offset = new Vector3(0,0.4f,0);

    public float zone_radius;

    private BuilderManager buildManager;

    // Start is called before the first frame update
    void Start()
    {
        buildManager = BuilderManager.Instance;
    }

    // Update is called once per frame
    void Update()
    {
      
    }

    void OnMouseDown()
    {
      
       Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
       RaycastHit hit;
       if(!Physics.Raycast(ray,out hit))
        {
            return;
        }
       
       if(!hit.collider)
        {
            return;
        }
       
        GameObject obj = hit.collider.gameObject;
        if(obj != gameObject)
        {
            return;
        }

        if(turret != null)
        {
            
        }
        else
        {
            BuildTurret(buildManager.GetCurrentBuild());
        }
    }

    void BuildTurret(GameObject prefabobj)
    {
        GameObject turret_d = Instantiate(prefabobj,transform.position + offset,Quaternion.identity);
        turret = turret_d;
    }

#if UNITY_EDITOR
    private void OnGUI()
    {
        var ch = transform.Find("ZoneCircle");
        if(ch == null)
        {
            GameObject cylinder = GameObject.CreatePrimitive(PrimitiveType.Cylinder);
            Vector3 position = cylinder.transform.position;
            position.y = 0.06f;
            cylinder.transform.position = position;
        }
        
    }
#endif
}
